package leetcode;

import java.util.Stack;

/**
 * Created with IntelliJ IDEA.
 * Description:剑指 Offer II 027. 回文链表
 * User: 东莞呵呵
 * Date:2022-07-19
 * Time:16:16
 */
public class TestDemo8 {
    public boolean isPalindrome(ListNode head) {
        Stack<ListNode> stack=new Stack<>();
        ListNode cur=head;
        while (cur!=null){
            stack.push(cur);
            cur=cur.next;
            if (cur.val==stack.peek().val){
                break;
            }
        }
        while(cur!=null&&!stack.isEmpty()){
            if(cur.val!=stack.peek().val){
                return false;
            }
            cur=cur.next;
            stack.pop();
        }
        return true;

    }
     class ListNode {
      int val;
      ListNode next;
      ListNode() {}
      ListNode(int val) { this.val = val; }
      ListNode(int val, ListNode next) { this.val = val; this.next = next; }
  }
}
